package com.yayyay.commom.utils;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @Author: liangSY
 * @Date: 2021/9/7 16:12
 * @ClassName: ResultBean
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class ResultBean<T> {

    //  未登录
    public static final int NO_LOGIN = -1;
    // 成功
    public static final int SUCCESS = 0;
    // 失败
    public static final int FAIL = 1;
    // 没有权限
    public static final int NO_PERMISSION = 2;

    private String msg;

    private int code;

    private T data;

    public ResultBean(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultBean(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultBean<T> success() {
        return new ResultBean<T>(SUCCESS, "success");
    }

    public static <T> ResultBean<T> success(String msg) {
        return new ResultBean<T>(SUCCESS, msg);
    }

    public static <T> ResultBean<T> success(T data) {
        return new ResultBean<T>(SUCCESS, "success", data);
    }

    public static <T> ResultBean<T> failed(int code, String msg) {
        return new ResultBean<T>(code, msg);
    }

    public static <T> ResultBean<T> failed(String msg) {
        return new ResultBean<T>(FAIL, msg);
    }
}
